package e.odbo.data.model;

public abstract class ColumnFlag {
    public static int BASE         =0x00;
    public static int NotNull      =0x02;
    public static int PK           =0x01|NotNull;
    public static int AutoGreater  =0x04;
    public static int Index        =0x08;
    public static int Unique       =0x10;

   public static boolean isPK(ColumnFlag flags){
       return (flags.flag&PK)==PK;
   }

    public static boolean isNotNull(ColumnFlag flags){
        return (flags.flag& NotNull)== NotNull;
    }

    public static boolean isAutoGreater(ColumnFlag flags){
        return (flags.flag&AutoGreater)==AutoGreater;
    }

    public static boolean isIndex(ColumnFlag flags){
        return (flags.flag&Index)==Index;
    }

    public static boolean isBase(ColumnFlag flags){
       return (flags.flag&0xff)==BASE;
    }

    public static boolean isUnique(ColumnFlag flags){return (flags.flag&Unique)==Unique;}

    private int flag;

    public ColumnFlag(){flag=BASE;}

    public ColumnFlag(int flag){
        this.flag=flag;
    }

    public static ColumnFlag build(int flag){
        return new ColumnFlag(flag) {};
    }

    public ColumnFlag and(int flag){
        this.flag=this.flag|flag;
        return this;
    }
}
